package com.xnyzc.lhy.didi.controller.invoice;

import com.xnyzc.lhy.common.component.didi.DiDiUrlConstant;
import com.xnyzc.lhy.common.entity.DiDiRv;
import com.xnyzc.lhy.common.exception.DiDiException;
import com.xnyzc.lhy.common.penum.EDiDiErrorCode;
import com.xnyzc.lhy.common.util.sign.AttestationTool;
import com.xnyzc.lhy.didi.entity.param.invoice.CancelInvoiceParam;
import com.xnyzc.lhy.didi.entity.param.invoice.InvoiceApplyForParam;
import com.xnyzc.lhy.didi.entity.param.invoice.InvoiceQueryParam;
import com.xnyzc.lhy.didi.entity.param.invoice.ResendInvoiceParam;
import com.xnyzc.lhy.didi.service.invoice.InvoiceService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 订单相关
 * </p>
 *
 * @author wangshuo
 * @since 2019-10-08
 */
@RestController
@RequestMapping("oa/didi/invoice")
public class InvoiceController {

    @Autowired
    private InvoiceService invoiceService;

    /**
     * 发票申请
     *
     * @param invoiceApplyForParam
     * @return
     */
    @ApiOperation(value = "发票申请", notes = "发票申请")
    @PostMapping(value = "/getInvoiceApplyFor")
    public DiDiRv getInvoiceApplyFor(@ApiParam(name =
            "invoiceApplyForParam", value = "发票申请") InvoiceApplyForParam invoiceApplyForParam) {
        if (!AttestationTool.getRequestSign(invoiceApplyForParam, invoiceApplyForParam.getSign(), DiDiUrlConstant.didiSignReq)) {
            throw DiDiException.create(EDiDiErrorCode.failureOfVerification);
        }
        return invoiceService.getInvoiceApplyFor(invoiceApplyForParam);
    }

    /**
     * 发票查询
     *
     * @param invoiceQueryParam
     * @return
     */
    @ApiOperation(value = "发票查询", notes = "发票查询")
    @PostMapping(value = "/getInvoiceQuery")
    public DiDiRv getInvoiceQuery(@ApiParam(name =
            "invoiceQueryParam", value = "发票查询") InvoiceQueryParam invoiceQueryParam) {
        if (!AttestationTool.getRequestSign(invoiceQueryParam, invoiceQueryParam.getSign(), DiDiUrlConstant.didiSignReq)) {
            throw DiDiException.create(EDiDiErrorCode.failureOfVerification);
        }
        return invoiceService.getInvoiceQuery(invoiceQueryParam);
    }

    /**
     * 重发发票
     *
     * @param resendInvoiceParam
     * @return
     */
    @ApiOperation(value = "重发发票", notes = "重发发票")
    @PostMapping(value = "/getResendInvoice")
    public DiDiRv getResendInvoice(@ApiParam(name =
            "resendInvoiceParam", value = "重发发票") ResendInvoiceParam resendInvoiceParam) {
        if (!AttestationTool.getRequestSign(resendInvoiceParam, resendInvoiceParam.getSign(), DiDiUrlConstant.didiSignReq)) {
            throw DiDiException.create(EDiDiErrorCode.failureOfVerification);
        }
        return invoiceService.getResendInvoice(resendInvoiceParam);
    }

    @ApiOperation(value = "发票作废", notes = "发票作废")
    @PostMapping(value = "/invoiceCancellation")
    public DiDiRv getInvoiceInvalidDiDi(@ApiParam(name =
            "invoiceInvalidDiDiParam", value = "发票作废") CancelInvoiceParam cancelInvoiceParam) {
        if (!AttestationTool.getRequestSign(cancelInvoiceParam, cancelInvoiceParam.getSign(), DiDiUrlConstant.didiSignReq)) {
            throw DiDiException.create(EDiDiErrorCode.failureOfVerification);
        }
        return invoiceService.getInvoiceInvalidDiDi(cancelInvoiceParam);
    }
}
